﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewData["Title"] = "湖北省检察院档案管理系统 - 个人 -我的文书档案";
}

<div class="Lawsuit-body">
    <table class="layui-table" id="table1" lay-filter="table1"></table>
</div>

<input type="hidden" value="@(ViewData["DAFL"])" id="DAFL"></input>

<script type="text/html" id="toolbar1">
    <div class="Lawsuit-tool-content">
        <div class="layui-btn-container Lawsuit-btn-container">
            <button type="button" class="layui-btn layui-btn-sm" lay-event="add">建立档案</button>
            <button type="button" class="layui-btn layui-btn-sm" lay-event="update">修改档案</button>
            <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete">删除档案</button>
        </div>
    </div>
</script>

@section scripts{
    <script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['form', 'index', 'table', 'laydate', 'layer', 'jquery'], function () {
        var form = layui.form, index = layui.index, table = layui.table, laydate = layui.laydate, layer = layui.layer, $ = layui.jquery;
        var DAFLa = $("#DAFL").val();
        var jh=[
                { field: 'xh', type: 'checkbox', LAY_CHECKED: true }
                , { field: 'FileNo', title: '档号', sort: true }
                , { field: 'FType', title: '问题', sort: true }
                , { field: 'ResponsiblePerson', title: '责任者', sort: true }
                , { field: 'ArticleNo', title: '文号', sort: true }
                , { field: 'Title', title: '案卷题名' }
                , { field: 'PageCount', title: '页数', sort: true  }
                , { field: 'FTerm', title: '期限' , sort: true }
                , { field: 'FRef', title: '盒号', sort: true  }
                , { field: 'BookNum', title: '件号' }
                , { field: 'FYear', title: '归档年度', sort: true  }
                , { field: 'ArticleDate', title: '文件形成时间', sort: true  }
                , { field: 'KeptFileDate', title: '归档日期' }
                , { field: 'DAMLDM', title: '档案门类代码' , sort: true }
                , { field: 'QZMC', title: '全宗名称', sort: true  }
                , { field: 'QZH', title: '全宗号', sort: true  }
                , { field: 'KZBS', title: '控制标识', sort: true  }
                , { field: 'MLevel', title: '密级' , sort: true }
                , { field: 'Remarks', title: '备注', sort: true }
        ]
        var ct=[
                { field: 'xh', type: 'checkbox', LAY_CHECKED: true }
                , { field: 'FileNo', title: '档号', sort: true }
                , { field: 'FTerm', title: '期限' , sort: true }
                , { field: 'FType', title: '问题', sort: true }
                , { field: 'FRef', title: '案卷号', sort: true }
                , { field: 'Title', title: '题名' }
                , { field: 'FYear', title: '归档年度', sort: true  }
                , { field: 'ArticleDate', title: '文件形成时间', sort: true  }
                , { field: 'KeptFileDate', title: '归档日期' }
                , { field: 'DAMLDM', title: '档案门类代码' , sort: true }
                , { field: 'QZMC', title: '全宗名称', sort: true  }
                , { field: 'QZH', title: '全宗号', sort: true  }
                , { field: 'KZBS', title: '控制标识', sort: true  }
                , { field: 'MLevel', title: '密级' , sort: true }
        ];
        var DAFL = DAFLa == "tradition" ? ct : jh;
        var talbe1 = table.render({
            elem: '#table1',
            toolbar: '#toolbar1',
            size: 'sm',
            height: 'full-60',
            cellMinWidth: '100',
            page:true,
            cols: [DAFL]
            , text: {
                none: '暂无数据！'
            }
            , data: [
                {}
            ]
       
        })

               table.on('toolbar(table1)',function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
              switch(obj.event){
                  case 'add':
                     top.layer.open({
                          type: 2,
                          title: '文书档案建档'
                          ,content:'/Personal/index/WritForm?type='+DAFLa
                          , area: ['800px', '600px']
                          , btn: ['保存', '关闭']
                          , yes: function (index, layero) {

                          },
                          btn2: function (index, layero) {

                          },
                            zIndex: layer.zIndex, //重点1
              success: function(layero){
                layer.setTop(layero); //重点2
              }
                      })
                break;
                  case 'update':
                    var checkStatusa = table.checkStatus('table1')
                    , checkData = checkStatusa.data; //得到选中的数据
                      
                      console.log(checkData.length === 0);
                      if (checkData.length === 0) {
                          return layer.msg('请选择数据');
                      } else {
                          top.layer.open({
                          type: 2,
                          title: '文书档案修改'
                          ,content:'/Personal/index/WritForm?type='+DAFLa
                          , area: ['800px', '600px']
                          , btn: ['保存', '关闭']
                          , yes: function (index, layero) {

                          },
                          btn2: function (index, layero) {

                              }
                          ,  zIndex: layer.zIndex, //重点1
          success: function(layero){
            layer.setTop(layero); //重点2
          }
                              })
                              }
                        break;  
                          case 'delete':
                              var checkStatusa = table.checkStatus('table1')
                            , checkData = checkStatusa.data; //得到选中的数据
                      
                              console.log(checkData.length === 0);
                              if (checkData.length === 0) {
                                  layer.msg('请选择数据');
                              } else {
                                  layer.msg('已删除 ', {icon:1});
                              }
                        break;
                    };        



                })
        
                                //单击行勾选checkbox事件
                $(document).on("click", ".layui-table-body table.layui-table tbody tr", function () {
                    /*当单击表格行时,把单选按钮设为选中状态*/
                    var tableDiv;
                    var index = $(this).attr('data-index');
                    var tableBox = $(this).parents('.layui-table-box');
                    //存在固定列
                    if (tableBox.find(".layui-table-fixed.layui-table-fixed-l").length > 0) {
                        tableDiv = tableBox.find(".layui-table-fixed.layui-table-fixed-l");
                    } else {
                        tableDiv = tableBox.find(".layui-table-body.layui-table-main");
                    }
                    var checkCell = tableDiv.find("tr[data-index=" + index + "]").find("td div.laytable-cell-checkbox div.layui-form-checkbox I");
                    if (checkCell.length > 0) {
                        checkCell.click();
                    }
                });

                //对td的单击事件进行拦截停止，防止事件冒泡再次触发上述的单击事件 
                $(document).on("click", "td div.laytable-cell-checkbox div.layui-form-checkbox", function (e) {
                    e.stopPropagation();
                });

     })
    </script>
}